#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

void test1(){
	int oldfd;
	oldfd=open("out.txt","w+",0644);
	close(1);
	int st=dup2(oldfd,1);
	close(oldfd);
	printf("hell  note this \n");

	close(st);
	dup2(st,1);
	close(st);
	printf("note this close old\n");

}

void test2(){
	int pfds[2]; 
	if(pipe(pfds)==0){
		if(fork()==0){
			close(1);
			dup2(pfds[1],1);
			close(pfds[0]);
			execlp("ls","ls","-l",NULL);
		}else{
			close(0);
			dup2(pfds[0],0);
			close(pfds[1]);
			execlp("wc","wc","-l",NULL);
		}
	}
}

int main(int argc,char** argv){
	test2();
}
